package com.wdh.kjs.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdh.kjs.R;
import com.wdh.kjs.activity.AddBankCardActivity;
import com.wdh.kjs.activity.ChooseBankActivity2;
import com.wdh.kjs.activity.MessageDetailsActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by chenqinhuang on 2016/4/20.
 */

public class ChooseBankCardAdapter extends BaseAdapter {
    private List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    private Context context;
    private HashMap<String, String> maps = new HashMap<String, String>();
    public ChooseBankCardAdapter(Context context, List<HashMap<String, String>> data) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.choose_bank2, null);
            viewHolder.choose_bank2_name = (TextView) convertView.findViewById(R.id.choose_bank2_name);
            viewHolder.choose_bank2_LinearLayout = (LinearLayout) convertView.findViewById(R.id.choose_bank2_LinearLayout);
            viewHolder.bank_logo =(ImageView)convertView.findViewById(R.id.bank_logo);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        maps = data.get(position);
//        ItemClick itemClick = new ItemClick(position);
//        viewHolder.choose_bank2_LinearLayout.setOnClickListener(itemClick);
        if (maps != null) {
            viewHolder.choose_bank2_name.setText(maps.get("choose_bank2_name"));
            switch (maps.get("choose_bank2_name")){
                case "农业银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_nongye); break;
                case "工商银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_gongshang); break;
                case "建设银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_jianshe); break;
                case "民生银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_minsheng); break;
                case "兴业银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_xingye); break;
                case "交通银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_jiaotong); break;
                case "中信银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_zhongxin); break;
                case "平安银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_pingan); break;
                case "广发银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_guangfa); break;
                case "招商银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_zhaoshang); break;
                case "中国银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_zhongguo); break;
                case "浦发银行":  viewHolder.bank_logo.setBackgroundResource(R.drawable.bc_pufa); break;
                default:  break;
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView choose_bank2_name;
        LinearLayout choose_bank2_LinearLayout;
        ImageView bank_logo;
    }

//    private class ItemClick implements View.OnClickListener{
//        private int Myposition;
//        public ItemClick(int position) {
//            Myposition = position;
//        }
//
//        @Override
//        public void onClick(View v) {
//            Intent intent = new Intent(context, AddBankCardActivity.class);
//            intent.putExtra("bandCardType", data.get(Myposition).get("choose_bank2_name"));
//            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//            context.startActivity(intent);
//        }
//    }
}